﻿<!DOCTYPE html>
<html>
<head>
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta charset="UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<title>城市资料管理</title>
</head>
<body>
	<h1>城市资料管理</h1>
	<div>
		条件cond：<input id="cond" value="" />
		省provinceId：<input id="provinceId" value="" />
		<input type="button" onclick="listByParams();" value="查找" />
	</div>
	<h2>
		<a href="add.html">新增</a>
	</h2>
	<table id="table"></table>
</body>
</html>
<script src="../../js/jquery.3.2.1.min.js"></script>
<script src="../../js/common.js"></script>
<script>
	function fun(id){
		alert(id);
	}
    listByParams();

    function listByParams() {
        var all = ajax(`/city/listByParams`, `get`, 
        	{
        		cond: $(`#cond`).val(),
        		provinceId: $(`#provinceId`).val(),
        		orderBy: `order by convert(t.name using 'gbk')`
        	}
        );
        var table = $(`#table`);
        table.empty();
        var th = 
        	`
        		<tr>
        			<th>id</th>
        			<th>provinceId</th>
        			<th>name</th>
        			<th>remark</th>
        			<th>操作</th>
        		</tr>
        	`;
        table.append(th);
        $.each(all, function (i, e) {
            var tr = `<tr>`;
            tr += `<td>${e.id}</td>`;
            tr += `<td>${e.provinceId}</td>`;
            tr += `<td>${e.name}</td>`;
            tr += `<td>${e.remark}</td>`;
            tr += `
            	<td>
	            	<a href="javascript:;" onclick="toUpdate('${e.id}')">编辑</a>
	            	<a href="javascript:;" onclick="toDelete('${e.id}')">删除</a>
            	</td>
            `;
            tr += `</tr>`;
            table.append(tr);
        });
    }

    function toUpdate(id) {
        location.href = 'update.html?id=' + id;
    }

    function toDelete(id) {
        var url = `/city/${id}`;
        // alert(url);
        if (!confirm(`删除操作不可恢复，是否继续？`)) return;
        var r = ajax(url, `delete`, {});
        alert(r.message);
        if (r.success) {
            location.reload();
        }
    }
</script>

































